//
//  MKTenEntranceCell.swift
//  MOKOAnnounce
//
//  Created by 曹相召 on 2017/7/11.
//  Copyright © 2017年 cc.moko. All rights reserved.
//  首页十个入口 cell

import UIKit

class MKTenEntranceCell: MKBaseTableViewCell,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout {

    var collectionView:UICollectionView!
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
    
        let layout:UICollectionViewFlowLayout = UICollectionViewFlowLayout.init()
        layout.minimumLineSpacing = 10
        layout.minimumInteritemSpacing = (ScreenWidth - 50 * 5 - 20) * 0.25
        layout.itemSize = CGSize.init(width: 50, height: 64)
        self.collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: layout)
        self.collectionView.backgroundColor = UIColor.white
        self.collectionView.delegate = self
        self.collectionView.dataSource = self
        self.collectionView.register(MKTenEntranceSubCell.classForCoder(), forCellWithReuseIdentifier: "MKTenEntranceSubCell")
        self.contentView.addSubview(self.collectionView)
    }
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 10
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell:MKTenEntranceSubCell = collectionView.dequeueReusableCell(withReuseIdentifier: "MKTenEntranceSubCell", for: indexPath) as! MKTenEntranceSubCell
        return cell
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        self.collectionView.frame = self.contentView.bounds
        self.collectionView.contentInset = UIEdgeInsetsMake(13, 10, 13, 10)
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}

class MKTenEntranceSubCell: UICollectionViewCell {
    var icon:UIImageView!
    var tip:UILabel!
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.icon = UIImageView.init()
        self.icon.backgroundColor = UIColor.randomColor()
        self.contentView.addSubview(self.icon)
        
        self.tip = UILabel.label(fontSize: 10, textColor: UIColorFromRGB(rgbValue: 0x333333, A: 1))
        self.tip.backgroundColor = UIColor.randomColor()
        self.tip.text = "公司发财"
        self.contentView.addSubview(self.tip)
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        self.icon.frame = CGRect.init(x: 0, y: 0, width: 50, height: 50)
        self.tip.sizeToFit()
        self.tip.frame = CGRect.init(x: (self.contentView.width - self.tip.width) * 0.5, y: self.icon.bottom + 4, width: self.tip.width, height: self.tip.height)
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
